package com.kongwg.exer;

import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.Date;

/**
 * @author kongwg
 * @create 2020-12-08 22:10
 */
public class NewDate {

    //将2017-11-12日转换为java.sql.Date
    @Test
    public void test(){
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

        TemporalAccessor parse = dateTimeFormatter.parse("2017-11-12");

        System.out.println(parse);



//        java.sql.Date sqlDate= new java.sql.Date();
    }

    @Test
    public void test1() throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

        Date parse = simpleDateFormat.parse("2017-11-12");

        java.sql.Date sqlDate = new java.sql.Date(parse.getTime());
        System.out.println(sqlDate);

    }
}
